// pages/business/business.js
var WxParse = require('../../../wxParse/wxParse.js');
var $ = require('../../../utils/js.js');

const app = getApp()
const common = require('../../../utils/common.js')
var img_gy_src = $.img_gy_src;
Page({
  // 页面的初始数据
  data: {
    img_gy_src: img_gy_src,
    shop_id: 0,
    latitude: 0,
    longitude: 0,
  },
  // 生命周期函数--监听页面加载
  onLoad: function(options) {
    $.ding_wei((data) => {
      console.log(data)
      this.setData({
        ding_wei: data.root
      })
      if (data.root) {
        this.setData({
          longitude: data.jing_du,
          latitude: data.wei_du,
        })
      }
      //动态推荐列表
      this.shop_detail_fun(this.data.longitude, this.data.latitude, options.id)
    })
  },
  // 生命周期函数--监听页面显示
  onShow: function() {

  },
  //店铺详情函数
  shop_detail_fun(longitude, latitude, shop_id) {
    var that = this;
    $.ajax({
      url: "/shops/detail",
      method: "GET",
      data: {
        longitude: longitude,
        latitude: latitude,
        shop_id: shop_id
      },
      success: function(res) {
        var data = res.data.data;
        if (data) {
          // 调用富文本函数
          WxParse.wxParse('fu_wen_ben', 'html', data.desc_content, that);
          that.setData({
            shop_detail: data,
          })
        } else {
          that.setData({
            shop_detail: null,
          })
        }
      }
    });
  },
  // 打开地图
  open_map(e) {
    $.open_map(this.data.shop_detail.longitude - 0, this.data.shop_detail.latitude - 0, this.data.shop_detail.shop_address);
  },
  tell(e) {
    let tell = e.currentTarget.dataset.tell
    common.tell(tell)
  }
})